package com.system.module.admin.controller;


import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import com.system.framework.aspect.lang.annotation.Log;
import com.system.framework.aspect.lang.enums.BusinessType;
import com.system.common.result.R;
import io.swagger.annotations.Api;
import com.system.module.admin.entity.Attendance;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import com.system.common.page.PageInfo;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import com.system.module.admin.service.IAttendanceService;
import com.system.module.admin.request.AttendanceRequest;

import javax.servlet.http.HttpServletResponse;

/**
 * 打卡记录控制层
 *
 * @author mars
 * @date 2024-04-13
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "打卡记录接口管理", tags = "打卡记录接口管理")
@RequestMapping("/admin/attendance")
public class AttendanceController {

    private final IAttendanceService iAttendanceService;

    /**
     * 分页查询打卡记录列表
     */
    @ApiOperation(value = "分页查询打卡记录列表")
    @PostMapping("/pageList")
    public R<PageInfo<Attendance>> pageList(@RequestBody AttendanceRequest attendanceRequest) {
        return R.success(iAttendanceService.pageList(attendanceRequest));
    }

    /**
     * 获取打卡记录详细信息
     */
    @ApiOperation(value = "获取打卡记录详细信息")
    @GetMapping(value = "/query/{id}")
    public R<Attendance> detail(@PathVariable("id") Integer id) {
        return R.success(iAttendanceService.getById(id));
    }

    /**
     * 新增打卡记录
     */
    @Log(title = "新增打卡记录", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增打卡记录")
    @PostMapping("/add")
    public R<Void> add(@RequestBody AttendanceRequest attendanceRequest) {
        iAttendanceService.add(attendanceRequest);
        return R.success();
    }

    /**
     * 修改打卡记录
     */
    @Log(title = "修改打卡记录", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改打卡记录")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody AttendanceRequest attendanceRequest) {
        iAttendanceService.update(attendanceRequest);
        return R.success();
    }

    /**
     * 删除打卡记录
     */
    @Log(title = "删除打卡记录", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除打卡记录")
    @DeleteMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Integer[] ids) {
        iAttendanceService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

}
